package cn.iocoder.yudao.module.resource.api;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.resource.api.enums.MessageContentTypeEnum;
import cn.iocoder.yudao.module.resource.api.enums.MessageSourceTypeEnum;
import cn.iocoder.yudao.module.resource.api.model.message.AudioDataDTO;
import cn.iocoder.yudao.module.resource.api.model.message.MessageDTO;
import cn.iocoder.yudao.module.resource.api.model.message.MessagePageReqDTO;
import cn.iocoder.yudao.module.resource.controller.admin.message.vo.MessagePageReqVO;
import cn.iocoder.yudao.module.resource.dal.dataobject.message.MessageDO;
import cn.iocoder.yudao.module.resource.service.message.MessageService;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.List;

@Service
public class MessageApiImpl implements IMessageApi {
    @Resource
    private MessageService messageService;

    @Override
    public MessageDTO getMessage(String id) {
        return BeanUtils.toBean(messageService.getMessage(id), MessageDTO.class);
    }

    @Override
    public MessageDTO getMessageByUserId(Long userId, String id) {
        return BeanUtils.toBean(messageService.getMessageByUserId(userId, id), MessageDTO.class);
    }

    @Override
    public PageResult<MessageDTO> getMessagePageByUserId(Long loginUserId, MessagePageReqDTO pageReq) {
        final PageResult<MessageDO> res = messageService.getMessagePageByUserId(loginUserId, BeanUtils.toBean(pageReq, MessagePageReqVO.class));
        return BeanUtils.toBean(res, MessageDTO.class);
    }

    @Override
    public void updateAudioDataById(String messageId, List<AudioDataDTO> audioDataList) {
        messageService.updateAudioDataById(messageId, BeanUtils.toBean(audioDataList, MessageDO.AudioData.class));
    }

    @Override
    public MessageDTO createMessage(String messageId, Long userId,
                                    MessageSourceTypeEnum senderType,
                                    MessageContentTypeEnum contentType,
                                    String gameMatchId, String wsSessionId,
                                    Integer roleId,
                                    String userText,
                                    String replyText,
                                    List<AudioDataDTO> audioDataList,
                                    Integer responseTimeMs) {
        final MessageDO message = messageService.createMessage(messageId, userId, senderType, contentType,
                gameMatchId, wsSessionId, roleId, userText, replyText,
                BeanUtils.toBean(audioDataList, MessageDO.AudioData.class), responseTimeMs);
        return BeanUtils.toBean(message, MessageDTO.class);
    }

    @Override
    public void deleteMessageByUserId(Long userId) {
        messageService.deleteMessageByUserId(userId);
    }
}
